Skip to content

Add percentage function - #413

Open
bowbowka wants to merge 1 commit into
python-humanize:mainfrom
bowbowka:feat/percentages-and-ratios
Open

bowbowka wants to merge 1 commit into
python-humanize:mainfrom
bowbowka:feat/percentages-and-ratios

Conversation

@bowbowka

Copy link
Copy Markdown

Fixes #277

Changes proposed in this pull request:

  • Add percentage() function to humanize.number to format numbers and ratios as percentages with customizable precision.
  • Export percentage in top-level humanize package (__all__).
  • Add comprehensive test cases in tests/test_number.py.
  • Update README.md with usage examples.

@Wkhanex Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Percentage formatting agrees with direct numeric formatting for negative, zero, fractional and large values, with ratio mode on/off and three precisions. Invalid inputs pass through as strings, and nonfinite values do not acquire a percent suffix.

Checked 5a4fb281ca51 with standalone Python 3.12.14 checks (47 passing assertions). I haven't run the full upstream suite. The generated _version module was supplied as metadata only; formatter code was unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Percentages and ratios

2 participants